﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.InventoryUI {
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Display.MarketUI.*;
    import org.aswing.event.*;
    import org.aswing.ext.*;
    import Display.aswingui.*;

    public class InventoryScrollingList extends MarketScrollingList {

        public static const NUM_INVENTORY_ITEMS:int = 10;
        public static const INVENTORY_SCROLLINGLIST_WIDTH_OFFSET:int = 7;

        protected var m_hideScrollButtons:Boolean;
        protected var m_initialized:Boolean = false;

        public function InventoryScrollingList(_arg1:Array, _arg2:Class, _arg3:int, _arg4:int=0, _arg5:int=2, _arg6:Boolean=false){
            this.m_hideScrollButtons = _arg6;
            super(_arg1, _arg2, _arg3, _arg4, _arg5);
        }
        protected function get assets():Dictionary{
            return (InventoryView.assetDict);
        }
        override protected function get scrollingListGap():int{
            return (-2);
        }
        override public function get numItems():int{
            return (NUM_INVENTORY_ITEMS);
        }
        override protected function makeButtons():void{
            var _local1:DisplayObject;
            var _local2:DisplayObject;
            var _local3:DisplayObject;
            var _local4:DisplayObject;
            var _local5:DisplayObject;
            var _local6:DisplayObject;
            if (!this.m_hideScrollButtons){
                _local1 = (new (this.assets["btn_prev_up"])() as DisplayObject);
                _local2 = (new (this.assets["btn_prev_over"])() as DisplayObject);
                _local3 = (new (this.assets["btn_prev_down"])() as DisplayObject);
                _local4 = (new (this.assets["btn_next_up"])() as DisplayObject);
                _local5 = (new (this.assets["btn_next_over"])() as DisplayObject);
                _local6 = (new (this.assets["btn_next_down"])() as DisplayObject);
                leftBtn = new JButton();
                leftBtn.wrapSimpleButton(new SimpleButton(_local1, _local2, _local3, _local1));
                rightBtn = new JButton();
                rightBtn.wrapSimpleButton(new SimpleButton(_local4, _local5, _local6, _local4));
                rightBtn.addActionListener(this.moveRight, 0, true);
                leftBtn.addActionListener(this.moveLeft, 0, true);
                leftBtn.setEnabled(false);
                if (m_data.length <= this.numItems){
                    rightBtn.setEnabled(false);
                };
            };
        }
        override protected function prepare():void{
            var _local1:JPanel;
            var _local2:JPanel;
            if (!this.m_hideScrollButtons){
                _local1 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
                _local1.append(leftBtn);
                _local1.append(ASwingHelper.verticalStrut(28));
                this.append(ASwingHelper.horizontalStrut(3));
                this.append(_local1);
                this.append(m_scrollPane);
                _local2 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
                _local2.append(rightBtn);
                _local2.append(ASwingHelper.verticalStrut(28));
                this.append(_local2);
            } else {
                this.append(m_scrollPane);
            };
            ASwingHelper.prepare(this);
            this.m_initialized = true;
        }
        override protected function initSize():void{
            m_scrollPane.setPreferredWidth((((Catalog.CARD_WIDTH + Catalog.CARD_OFFSET) + INVENTORY_SCROLLINGLIST_WIDTH_OFFSET) * m_columns));
        }
        public function invalidateData():void{
            var _local1:int;
            var _local2:InventoryCell;
            if (this.m_initialized){
                _local1 = 0;
                while (_local1 < m_data.length) {
                    _local2 = (m_dataList.getCellByIndex(_local1) as InventoryCell);
                    if (_local2 != null){
                        _local2.invalidateData();
                    };
                    _local1++;
                };
            };
        }
        override protected function makeData():void{
            var _local1:int = Math.min(this.numItems, m_data.length);
            m_model = new VectorListModel();
            var _local2:int;
            while (_local2 < _local1) {
                m_model.append(m_data[_local2]);
                m_curCount++;
                _local2++;
            };
            m_dataList = new GridList(m_model, m_cellFactory, m_columns, m_rows);
            m_dataList.setHolderLayout(new GridListHorizontalLayout(m_rows, m_columns, 0, 0));
            m_scrollPane = new JScrollPane(m_dataList, JScrollPane.SCROLLBAR_NEVER, JScrollPane.SCROLLBAR_NEVER);
        }
        override protected function get scrollingListWidth():Number{
            return ((((Catalog.CARD_WIDTH + Catalog.CARD_OFFSET) + INVENTORY_SCROLLINGLIST_WIDTH_OFFSET) * m_columns));
        }
        override public function scrollToItemIndex(_arg1:int):void{
            if ((((_arg1 < 0)) || ((_arg1 >= m_data.length)))){
                return;
            };
            while (_arg1 < m_curIndex) {
                this.moveLeft(null);
            };
            while (_arg1 >= (m_curIndex + this.numItems)) {
                this.moveRight(null);
            };
        }
        override protected function moveRight(_arg1:AWEvent):void{
            var _local4:int;
            var _local2:int = m_curCount;
            var _local3:int = Math.min(m_data.length, (m_curCount + this.numItems));
            if ((_local3 - _local2) > 0){
                if (m_model.getSize() < (this.numItems + m_curCount)){
                    _local4 = _local2;
                    while (_local4 < _local3) {
                        m_model.append(m_data[_local4]);
                        m_curCount++;
                        _local4++;
                    };
                };
            };
            m_curIndex = Math.min((m_curIndex + this.numItems), (m_data.length - 1));
            if (m_curIndex >= (m_data.length - this.numItems)){
                rightBtn.setEnabled(false);
            };
            leftBtn.setEnabled(true);
            m_dataList.scrollHorizontal(this.scrollingListWidth);
        }
        override protected function moveLeft(_arg1:AWEvent):void{
            m_curIndex = Math.max((m_curIndex - this.numItems), 0);
            if (m_curIndex <= 0){
                leftBtn.setEnabled(false);
                m_curIndex = 0;
            };
            rightBtn.setEnabled(true);
            m_dataList.scrollHorizontal(-(this.scrollingListWidth));
        }
        override public function get currentItem():int{
            return (m_curIndex);
        }
        override public function updateElements():void{
            var _local2:InventoryCell;
            var _local1:int;
            while (_local1 < m_dataList.getCells().getSize()) {
                _local2 = (m_dataList.getCellByIndex(_local1).getCellComponent() as InventoryCell);
                if (_local2){
                    _local2.performUpdate();
                };
                _local1++;
            };
        }

    }
}//package Display.InventoryUI 
